<?php
namespace App\Http\ViewComposers;

use App\Member;
use EasyWeChat\Foundation\Application;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;

class WxComposer
{

    protected $wechat;
    protected $httpHost;

    /**
     * 创建一个新的属性composer.
     *
     * @param UserRepository $users
     * @return void
     */
    public function __construct(Application $wechat,Request $request)
    {
        $this->wechat = $wechat;
        $this->httpHost = $request->getSchemeAndHttpHost();

    }

    /**
     * 绑定数据到视图.
     *
     * @param View $view
     * @return void
     */
    public function compose(View $view)
    {
        $member = $this->member();
        $this->wechat->js->setUrl($this->currentUrl());
        $view->with('member', $member);

    }

    protected function member() {
        return session('member');
    }


    protected function currentUrl()
    {
        if (defined('PHPUNIT_RUNNING')) {
            return 'http://localhost';
        }

        $protocol = 'http://';



        return $protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    }
}
